home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 45
/
Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso
/
Aminet
/
dev
/
gui
/
titlebar_ic.lha
/
titlebar_ic
/
TBITest.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-01-20
|
8KB
|
225 lines
/* Titlebar.image test (19.1.2001) */
/* Written for SAS/C */
/* Compile: SC LINK TBITest */
/* © 2001 Massimo Tantignone */
/* e-mail: tanti@intercom.it */
#include "exec/types.h"
#include "dos/dos.h"
#include "intuition/intuition.h"
#include "intuition/gadgetclass.h"
#include "intuition/imageclass.h"
#include "libraries/gadtools.h"
#include "proto/intuition.h"
#include "proto/exec.h"
#include <images/titlebar.h>
#include <clib/titlebarimage_protos.h>
#include <pragmas/titlebarimage_pragmas.h>
/* The library base for the "titlebar.image" class library */
struct Library *TitlebarImageBase;
ULONG main(void)
{
/* The usual stuff */
struct Screen *scr;
struct Window *win;
struct IntuiMessage *imsg;
struct DrawInfo *dri;
ULONG class, code, done = FALSE;
ULONG width = 640, height = 200;
struct Gadget *gad;
struct Image *i;
/* Let's try to open the "titlebar.image" class library any way we can */
TitlebarImageBase = OpenLibrary("titlebar.image",40L);
if (!TitlebarImageBase)
TitlebarImageBase = OpenLibrary("Images/titlebar.image",40L);
if (!TitlebarImageBase)
TitlebarImageBase = OpenLibrary("Classes/Images/titlebar.image",40L);
/* Really not found? Then quit (and complain a bit) */
if (!TitlebarImageBase) return (RETURN_FAIL);
/* Lock the current default public screen */
if (scr = LockPubScreen(NULL))
{
/* Inquire about the real screen size */
width = scr->Width;
height = scr->Height;
/* Get the screen's DrawInfo, it will be useful... */
if (dri = GetScreenDrawInfo(scr))
{
/* Create an instance of the "tbiclass" image class */
if (i = NewObject(NULL,"tbiclass",SYSIA_Which,ICONIFYIMAGE,
SYSIA_DrawInfo,dri,
TAG_END))
{
/* Attempt to create a gadget to go into the titlebar; */
/* of course it will use our new "tbiclass" image. */
/* Here we pass 2 to TBI_RELPOS() because there will be 2 */
/* gadgets at the right side of our new gadget in the */
/* window titlebar: the zoom gadget and the depth gadget. */
/* If we were to add another gadget to the left of this one, */
/* we would pass 3 for it, then 4 for a third, and so on. */
if (gad = NewObject(NULL,"buttongclass",
GA_RelRight,TBI_RELPOS(i,2),
GA_Top,0,
GA_Width,i->Width - 1,
GA_Height,i->Height,
GA_TopBorder,TRUE,
GA_Image,i,
GA_RelVerify,TRUE,
TAG_END))
{
/* Open a window on the default public screen */
if (win = OpenWindowTags(NULL,WA_Left,(width - 400) / 2,
WA_Top,(height - 250) / 2,
WA_Width,400,WA_Height,250,
WA_CloseGadget,TRUE,
WA_DepthGadget,TRUE,
WA_SizeGadget,TRUE,
WA_DragBar,TRUE,
WA_Gadgets,gad,
WA_SimpleRefresh,TRUE,
WA_Activate,TRUE,
WA_Title,"titlebar.image test",
WA_IDCMP,IDCMP_CLOSEWINDOW |
IDCMP_REFRESHWINDOW |
IDCMP_GADGETUP,
TAG_END))
{
ULONG a, b, t = 0L;
struct Image *v;
/* Show the various image types */
for (a = 0; a < 3; a++)
{
for (b = 0; b < 2; b++)
{
if (v = NewObject(NULL,"tbiclass",
SYSIA_Which,POPUPIMAGE + t++,
SYSIA_DrawInfo,dri,
TAG_END))
{
DrawImageState(win->RPort,v,
50 + a * 100,50 + b * 100,
IDS_NORMAL,dri);
DrawImageState(win->RPort,v,
90 + a * 100,50 + b * 100,
IDS_SELECTED,dri);
DrawImageState(win->RPort,v,
50 + a * 100,90 + b * 100,
IDS_INACTIVENORMAL,dri);
DrawImageState(win->RPort,v,
90 + a * 100,90 + b * 100,
IDS_INACTIVESELECTED,dri);
WaitBlit();
DisposeObject(v);
}
}
}
/* Put our iconify gadget to the front so it can be used */
/* We passed it also at window opening so that patches */
/* centering window titles could compute the correct */
/* title position right from the start. */
RemoveGadget(win,gad);
AddGadget(win,gad,0);
/* Let's handle the events until the window gets closed */
while (!done)
{
Wait(1 << win->UserPort->mp_SigBit);
while (imsg = (struct IntuiMessage *)GetMsg(win->UserPort))
{
class = imsg->Class;
code = imsg->Code;
ReplyMsg((struct Message *)imsg);
if (class == IDCMP_CLOSEWINDOW) done = TRUE;
if (class == IDCMP_GADGETUP)
{
/* This was a message from our iconify gadget: */
/* let's do something to show we received it. */
DisplayBeep(NULL);
}
if (class == IDCMP_REFRESHWINDOW)
{
BeginRefresh(win);
EndRefresh(win,TRUE);
}
}
}
/* Say good-bye to the window... */
CloseWindow(win);
}
/* ... to the gadget... */
DisposeObject(gad);
}
/* ... and to the image */
DisposeObject(i);
}
/* Release the DrawInfo structure */
FreeScreenDrawInfo(scr,dri);
}
/* Finally unlock the screen */
UnlockPubScreen(NULL,scr);
}
/* Close the class library */
CloseLibrary(TitlebarImageBase);
/* We did our job, now let's go home :-) */
return (RETURN_OK);
}